unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IniFiles, unitSaveSettings;

type
  TForm2 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Edit1: TEdit;
    CheckBox1: TCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    CheckBox2: TCheckBox;
    GroupBox3: TGroupBox;
    Label4: TLabel;
    CheckBox3: TCheckBox;
    Edit4: TEdit;
    Label5: TLabel;
    Edit5: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
  private
    BPort: String;
    BAddress: String;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}
{
procedure Renew;
var
  Ini: TIniFile;
begin
  //Form1.LoadSettings;
  unitSaveSettings.LoadSettingsFromIniFiles;

  Form2.CheckBox1.Checked := Form1.bExtThreadsVisualization;
  Form2.CheckBox2.Checked := Form1.bExtLogFile;
  Form2.CheckBox3.Checked := Form1.bUseEvilCompression;
  Form2.Edit1.Enabled := Form2.CheckBox1.Checked;
  Form2.Edit5.Enabled := Form2.CheckBox3.Checked;
  Form2.Edit1.Text := IntToStr(Form1.ShowTime);
  Ini := TIniFile.Create(Form1.EXEPath + 'servers.ini');
  Form2.Edit3.Text := IntToStr(Ini.ReadInteger('server0', 'Port', 0));
  Form2.Edit2.Text := Ini.ReadString('server0', 'BackyardAddress', '');
  Form2.Edit4.Text := IntToStr(Form1.ShowTime);
  Form2.Edit5.Text := IntToStr(Form1.iMaxCPUUsage);
  Ini.Free;
end;     }

procedure TForm2.Button1Click(Sender: TObject);
begin
  Close;
end;

procedure TForm2.CheckBox1Click(Sender: TObject);
begin
  Form2.Edit1.Enabled := Form2.CheckBox1.Checked;
end;

procedure TForm2.CheckBox3Click(Sender: TObject);
begin
  Form2.Edit5.Enabled := Form2.CheckBox3.Checked;
end;

procedure TForm2.FormShow(Sender: TObject);
begin
{  Renew;
  BAddress := Form2.Edit2.Text;
  BPort := Form2.Edit3.Text;  }
end;

procedure TForm2.Button2Click(Sender: TObject);
var
  Ini: TIniFile;
  Changes: BOOL;
begin
{  Changes := (Edit2.Text <> BAddress) or (Edit3.Text <> BPort);

  if StrToInt(Edit1.Text) < 1000 then
    Edit1.Text := '1000';

  if (StrToInt(Edit5.Text) > 100) or (StrToInt(Edit5.Text) < 0) then
    Edit5.Text := '100';

  Ini := TIniFile.Create(Form1.EXEPath + 'settings.ini');

  Ini.WriteInteger('visuals', 'showtime', StrToInt(Edit1.Text));

  if CheckBox1.Checked then
    Ini.WriteString('visuals', 'extthreads', 'true')
  else
    Ini.WriteString('visuals', 'extthreads', 'false');

  if CheckBox2.Checked then
    Ini.WriteString('visuals', 'extlogfile', 'true')
  else
    Ini.WriteString('visuals', 'extlogfile', 'false');

  Ini.Free;

  Ini := TIniFile.Create(Form1.EXEPath + 'servers.ini');
  Ini.WriteString('server0', 'BackyardAddress', Edit2.Text);
  Ini.WriteInteger('server0', 'Port', StrToInt(Edit3.Text));

  if CheckBox3.Checked then
    Ini.WriteString('server0', 'compression', 'true')
  else
    Ini.WriteString('server0', 'compression', 'false');

  Ini.WriteInteger('server0', 'maxcpuusage', StrToInt(Edit5.Text));

  Ini.WriteInteger('server0', 'timeout', StrToInt(Edit4.Text));

  Ini.Free;

  Renew;
  BAddress := Form2.Edit2.Text;
  BPort := Form2.Edit3.Text;

  if Changes then
    ShowMessage('To apply this configuration you must restart program');     }
end;

end.
